What is netrc?
The netrc npm package is used to read and write .netrc files, which are used to store credentials for remote systems. This package allows developers to programmatically manage these credentials, making it easier to automate tasks that require authentication.
What are netrc's main functionalities?
Read .netrc file
This feature allows you to read the .netrc file and retrieve stored credentials. The code sample demonstrates how to use the netrc package to read the .netrc file and log the credentials to the console.
const netrc = require('netrc');
const credentials = netrc();
console.log(credentials);
Write to .netrc file
This feature allows you to write new credentials to the .netrc file. The code sample shows how to add credentials for 'example.com' and save them to the .netrc file.
const netrc = require('netrc');
let credentials = netrc();
credentials['example.com'] = { login: 'user', password: 'pass' };
netrc.save(credentials);
Other packages similar to netrc
netrc-parser
The netrc-parser package provides similar functionality to netrc, allowing users to parse and manipulate .netrc files. It offers a more object-oriented approach and additional methods for handling .netrc entries, which might be preferred by developers looking for more structured code.
node-netrc
node-netrc is another package for handling .netrc files. It provides basic functionality to read and write .netrc files, similar to netrc, but with a simpler API. It might be suitable for users who need straightforward operations without additional features.
netrc
Parse netrc files
Usage
var netrc = require('netrc');
var myNetrc = netrc();
console.log(myNetrc['github.com'])
myNetrc['github.com'].login = 'my-new-oauth-token';
netrc.save(myNetrc);
API
netrc([file])
Loads a .netrc
file, defaulting to ~/.netrc
netrc.parse(string)
Parses netrc formatted string into an object:
{
"machine1.example.com": {
"login": "my-login",
"password": "my-password"
},
"machine2.example.com": {
"login": "my-other-login",
"password": "my-other-password"
}
}
netrc.format(object)
Formats a netrc object into a valid string
netrc.save(object)
Persists a netrc object to ~/.netrc
Tests
$ npm test